package l1j.server.server.model;

import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;

import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.serverpackets.S_SkillSound;//TODO HPR效果
import l1j.server.server.serverpackets.S_SystemMessage;

public class HpRegenerationByDoll extends TimerTask {
	private static Logger _log = Logger.getLogger(HpRegenerationByDoll.class.getName());

	private final L1PcInstance _pc;

	public HpRegenerationByDoll(final L1PcInstance pc) {
		this._pc = pc;
	}

	//TODO 魔法娃娃DB化魔法娃娃額外追加的HPR
	private void regenHp() {
		final int hpr = this._pc.getDollList().getDollHprTime();
		if(hpr >0){
			final int newHp = Math.max(0, this._pc.getCurrentHp() + hpr);
			this._pc.sendPackets(new S_SkillSound(this._pc.getId(), 6321));//修正特效編號錯誤問題by0968026609
			this._pc.sendPackets(new S_SystemMessage("突然感到全身充滿力量,體力恢復了許多。"));
			this._pc.setCurrentHp(newHp);
		}
	}

	@Override
	public void run() {
		try {
			if (this._pc.isDead()) {
				return;
			}
			this.regenHp();
		} catch (final Exception  e) {
			_log.log(Level.WARNING, e.getLocalizedMessage(), e);
		}
	}


}
